package com.sojson.controller.po;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.sojson.constant.ConstantByMap;
import com.sojson.result.Result;
import com.sojson.util.ToolsUtil;

import io.swagger.annotations.Api;

/**
 * 文件控制器
 * 
 * @author liu
 * @date 2021-03-18
 */
@Api(tags = "文件管理")
@RestController
@RequestMapping("/file")
public class FileController {

    /**
     * 上传头像
     * 
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/uploadHead")
    public Result<?> uploadHead(MultipartFile file) throws Exception {
        return ToolsUtil.upload(file, ToolsUtil.HEAD_IMG_PATH, ToolsUtil.IMG_WHITE_LIST, ToolsUtil.IMG_SIZE);
    }

    /**
     * 上传企业资质照片
     * 
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/uploadBusinessCert")
    public Result<?> uploadBusinessCert(MultipartFile file) throws Exception {
        return ToolsUtil.upload(file, ToolsUtil.BUSINESS_CERT_IMG_PATH, ToolsUtil.IMG_WHITE_LIST, ToolsUtil.IMG_SIZE);
    }

    /**
     * 上传商品分类缩略图
     * 
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/uploadGoodCateThumb")
    public Result<?> uploadGoodCateThumb(MultipartFile file) throws Exception {
        return ToolsUtil.upload(file, ToolsUtil.GOOD_CATE_THUMB, ToolsUtil.IMG_WHITE_LIST, ToolsUtil.IMG_SIZE);
    }

    /**
     * 上传商品缩略图
     * 
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/uploadGoodThumb")
    public Result<?> uploadGoodThumb(MultipartFile file) throws Exception {
        return ToolsUtil.upload(file, ToolsUtil.GOOD_THUMB, ToolsUtil.IMG_WHITE_LIST, ToolsUtil.IMG_SIZE);
    }

    /**
     * 上传商品详情轮播图
     * 
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/uploadGoodImages")
    public Result<?> uploadGoodImages(MultipartFile file) throws Exception {
        return ToolsUtil.upload(file, ToolsUtil.GOOD_IMAGES, ToolsUtil.IMG_WHITE_LIST, ToolsUtil.IMG_SIZE);
    }

    /**
     * 上传商品规格明细缩略图
     * 
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/uploadGoodSpecsAttrThumb")
    public Result<?> uploadGoodSpecsAttrThumb(MultipartFile file) throws Exception {
        return ToolsUtil.upload(file, ToolsUtil.GOOD_SPECS_ATTR_THUMB, ToolsUtil.IMG_WHITE_LIST, ToolsUtil.IMG_SIZE);
    }

    /**
     * 上传商品规格明细缩略图
     * 
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/uploadComment")
    public Result<?> uploadComment(MultipartFile file) throws Exception {
        return ToolsUtil.upload(file, ToolsUtil.COMMENT_IMG_PATH, ToolsUtil.IMG_WHITE_LIST, ToolsUtil.IMG_SIZE);
    }

    /**
     * 上传头像
     * 
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/uploadIdCard")
    public Result<?> uploadIdCard(MultipartFile file) throws Exception {
        return ToolsUtil.upload(file, ToolsUtil.ID_CARD, ToolsUtil.IMG_WHITE_LIST, ToolsUtil.IMG_SIZE);
    }

    /**
     * 上传广告图片
     * 
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/uploadAd")
    public Result<?> uploadAd(MultipartFile file) throws Exception {
        return ToolsUtil.upload(file, ToolsUtil.AD, ToolsUtil.IMG_WHITE_LIST, ToolsUtil.IMG_SIZE);
    }

    /**
     * 上传许可证图片
     * 
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/uploadBusinessLicense")
    public Result<?> uploadBusinessLicense(MultipartFile file) throws Exception {
        return ToolsUtil.upload(file, ToolsUtil.BUSINESS_LICENSE, ToolsUtil.IMG_WHITE_LIST, ToolsUtil.IMG_SIZE);
    }

    /**
     * 上传图片
     * 
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/upload")
    public Result<?> upload(MultipartFile file) throws Exception {
        return ToolsUtil.upload(file, ConstantByMap.DEFAULT, ToolsUtil.IMG_WHITE_LIST, ToolsUtil.IMG_SIZE);
    }

    /**
     * 上传图片
     * 
     * @param files
     * @return
     * @throws Exception
     */
    @PostMapping("/uploadList")
    public Result<?> uploadList(MultipartFile[] file) throws Exception {
        return ToolsUtil.upload(file, ConstantByMap.DEFAULT, ToolsUtil.IMG_WHITE_LIST, ToolsUtil.IMG_SIZE);
    }

    /**
     * 上传推广海报背景图
     * 
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/uploadBgPromotionPoster")
    public Result<?> uploadBgPromotionPoster(MultipartFile file) throws Exception {
        return ToolsUtil.upload(file, ConstantByMap.DEFAULT, ToolsUtil.IMG_WHITE_LIST, ToolsUtil.IMG_SIZE);
    }

}